""" 
  淘宝模拟登陆
"""


import requests
from bs4 import BeautifulSoup
from selenium import webdriver
from lxml import etree
from time import sleep

def main():
  browserDriver = webdriver.Chrome()
  to_login(browserDriver)
  # browserDriver.quit()


def to_login( Bdriver ):
  Bdriver.get('http://www.taobao.com')
   # 填写登录信息
  user_name = '15738513616'
  user_password = 'ysr869wwwk'
  try: 
    # 去登录页
    login_ele = Bdriver.find_element_by_link_text('亲，请登录')   # 搜索登录按钮
    login_ele.click()
    sleep(2)

    # 使用密码登陆
    Bdriver.find_element_by_class_name('password-login-tab-item').click()
    sleep(1)
    Bdriver.find_element_by_class_name('sms-login-tab-item').click()
    sleep(1)
    Bdriver.find_element_by_class_name('password-login-tab-item').click()
    sleep(1)

    Bdriver.refresh()
    # 写入用户名和密码
    Bdriver.find_element_by_id('fm-login-id').send_keys(user_name)
    sleep(1)
    Bdriver.find_element_by_id('fm-login-password').send_keys(user_password)
    sleep(10)
    # try:
    #   # Bdriver.find_element_by_css_selector('.fm-button,.fm-submit,.password-login').click()
    #   sleep(10)
    # except:
    #   print('登录操作失败')
  except:
    print('登录按钮没有获取到')



main()
